﻿var xmlHttpAjax;

function GetXmlHttpObject() {
    var xmlHttpAjax = null;
    try {
        xmlHttpAjax = new XMLHttpRequest(); /* Firefox, Opera 8.0+, Safari*/
    } catch (e) {
        try {
            xmlHttpAjax = new ActiveXObject("Msxml2.XMLHTTP"); /* Internet Explorer*/
        } catch (e) {
            xmlHttpAjax = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttpAjax;
}

function CheckXmlHttp() {
    if (xmlHttpAjax != null) {
        xmlHttpAjax.abort();
        xmlHttpAjax = null;
    }
    xmlHttpAjax = GetXmlHttpObject();

    if (xmlHttpAjax == null) {
        alert("您的浏览器不支持AJAX！");
        return false;
    }
    return true;
}

function HttpOpen(url, resultControlID) {
    if (CheckXmlHttp() == false) return;
    xmlHttpAjax.open("GET", url, true);
    if (resultControlID != null) xmlHttpAjax.onreadystatechange = function () { stateChanged(resultControlID) };
    xmlHttpAjax.send(null);
}

function stateChanged(resultControlID) {
    if (xmlHttpAjax.readyState == 4 && xmlHttpAjax.status == 200) {
        var result = xmlHttpAjax.responseText;
        if (resultControlID != null) $.el(resultControlID).innerHTML = result;
    }
}

function HttpOpen(url, resultControlID, fun) {
    if (CheckXmlHttp() == false) return;
    xmlHttpAjax.open("GET", url, true);
    if (resultControlID != null) xmlHttpAjax.onreadystatechange = function () { fun(resultControlID) };
    xmlHttpAjax.send(null);
}

function SetMainContentValue(resultControlID) {
    if (xmlHttpAjax.readyState == 4 && xmlHttpAjax.status == 200) {
        var result = xmlHttpAjax.responseText;
        var data = result.split("▕,");
        for (var i = 0; i < data.length; i++) {
            data[i] = data[i].split("▏,");
        }
        addHighcharts(resultControlID, data);
    }
}

